<template>
	<view>
		<custom title="设置" mode="2" fixed="fixed"> </custom>

		<view class="flex">
			<view class="flex-content">


				<cell-list class="mt-20">
					<cell title="账户" @click="toPage('/pages/setting/acount')"></cell>
				</cell-list>
				
				

				<cell-list class="mt-20">
					<cell title="通用" @click="toPage('/pages/setting/common')"></cell>
				</cell-list>
				
				<cell-list class="mt-20">
					<cell title="青少年模式" @click="toPage('/pages/setting/teenagemode')"></cell>
				</cell-list>
				
				<cell-list class="mt-20">
					<cell title="举报" @click="toPage('/pages/setting/report')"></cell>
				</cell-list>
				
				<!-- <cell-list class="mt-20">
					<cell title="地址管理" @click="toPage('/pages/address/list')"></cell>
				</cell-list> -->

				<cell-list class="mt-20">
					<cell title="清理缓存" @click="clear_cache"></cell>
					<cell title="故障反馈" @click="toPage('/pages/user/feedback')"></cell>
				</cell-list>

				<!-- <cell-list class="mt-20">
					<cell title="个性化推荐" type="none">
						<view class="pr" slot="right">
							<switch style="height: 34rpx;transform: scale(0.7) translateX(20rpx);" color="#FD8757"
								:checked="GXH">
							</switch>
							<view style="position: absolute;width: 100%;height: 100%;left:0;top:0;z-index: 2;"
								@tap.stop="change_gxh"></view>
						</view>
					</cell>
				</cell-list> -->




				<cell-list class="mt-30">
					<cell title="" type="none" @click="logout">
						<view class="fs-30 flex-1 flex flex-x-y" slot="titleRight">退出登录</view>
					</cell>
				</cell-list>





			</view>
		</view>

		<toast ref="toast"></toast>
	</view>
</template>

<script>
	import { TUILogin } from '@tencentcloud/tui-core';
	let envinfo = require("../../siteinfo.js");
	export default {
		data() {
			return {
				envinfo: envinfo,
				GXH: true,
			};
		},
		onLoad() {
			let gxh = uni.getStorageSync('GXH');
			if (gxh !== '') {
				this.GXH = gxh;
			}
		},
		methods: {
			logout() {
				this.$refs.toast.open({
					desc: "确定退出登录？",
					left: "我再想想",
					right: "退出",
					success: () => {
						this.less(() => {
							this.request({
								url: "/login/loginOut",
								method: "POST",
							}).then((res) => {
								// uni.$emit('logout');
								this.vuexSet("user_info", {}, true);
								uni.setStorageSync("ACCESS_TOKEN", "");
								uni.setStorageSync("userSig", "");
								TUILogin.logout();
								uni.setStorageSync("TIKTOK_PARTNER_AGGREMENT", "");
								uni.redirectTo({
									url: "/pages/login/login",
								});

								if (getApp().globalData.CHAT && getApp().globalData.CHAT
									.CLOSE) {
									getApp().globalData.CHAT.CLOSE();
								}
							});
						});
					},
				});
				uni.setStorage({
					key: "openid",
					data: "",
				});
			},
			choose_image() {
				uni.chooseImage({
					sourceType: ['album'],
					count: 1,
					success: (res) => {
						let {
							tempFilePaths = []
						} = res;
						console.log("res", res);
						tempFilePaths.forEach((val) => {
							// #ifdef APP-PLUS
							uni.compressImage({
								src: val,
								width: "200",
								success: (img) => {
									this.upload_image(img.tempFilePath);
									console.log("img.tempFilePath", img.tempFilePath);
								},
								fail: (err) => {
									console.log("err", err);
								},
							});
							// #endif

							// #ifdef H5
							this.upload_image(val);
							// #endif
						});
					},
				});
			},
			upload_image(url) {
				uni.showLoading({
					title: "上传图片中",
					mask: true,
				});
				let appUrl = "/api/common/uploadImages";

				appUrl = envinfo.root + appUrl;

				uni.uploadFile({
					url: appUrl,
					filePath: url,
					data: {
						photo: "img",
						name: "img",
					},
					name: "img",
					header: {
						token: uni.getStorageSync("ACCESS_TOKEN"),
					},
					success: (img_data) => {
						uni.hideLoading();
						let data = JSON.parse(img_data.data);
						if (
							img_data.statusCode == 200 &&
							img_data.errMsg == "uploadFile:ok"
						) {
							if (data.status == 200 && data.data && data.data.imgUrl) {
								this.request({
									url: "/wjuser/user",
									loading: true,
									data: {
										avatarUrl: data.data.imgUrl,
										id: this.user_info.id,
									},
									method: "PUT",
									loading: true,
								}).then((res) => {
									if (res.status == 200) {
										this.showToast("修改成功");
									}
								});
							} else {}
						} else {
							this.$refs.toast.open({
								desc: data?.msg || "请稍后重试",
							});
							// this.showToast(data.msg || '请稍后重试');

							if (data.status == 403 || data.status == 4006) {
								// this.toPage('/pages/login/login')
							}
						}
					},
					complete: (res) => {},
					fail: (res) => {
						this.$refs.toast.open({
							desc: data.msg || "请稍后重试",
						});
					},
				});
			},
			clear_cache() {
				uni.showLoading({
					title: '清理中',
					mask: true
				});
				setTimeout(() => {
					uni.hideLoading();
					this.showToast('清理成功');
				}, 5000);

			},
			change_gxh() {
				if (this.GXH == false) {
					this.GXH = true;
					uni.setStorageSync('GXH', true);
					return;
				}
				this.$refs.toast.open({
					desc: '关闭后，你在信友圈将无法查看到好友的动态',
					success: () => {
						this.GXH = false;
						uni.setStorageSync('GXH', false);
					}
				});

			},
		},
	};
</script>

<style>
	page {
		background-color: #f0f2f5;
	}

	.item-list-box {
		border-bottom: 2rpx solid #eeeeee;
		color: #323232;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 30rpx 30rpx 30rpx 40rpx;
		line-height: 30rpx;
	}

	.setting-item {
		height: 112rpx;
		background-color: #ffffff;
		padding-right: 30rpx;
		color: #333 !important;
	}

	.setting-item>view {
		/* color: rgba(255, 255, 255, 1); */
	}

	.setting-item+.setting-item {
		/* border-top: 0.5px solid #D8D8D8; */
		border-top: 0.5px solid #eeeeee;
	}

	.abcd {
		height: 108rpx;
		background: #ffffff;

		color: #333;
	}
</style>